package com.gateway.pay.channel.dto;

import lombok.Data;

@Data
public class Result<T> {
    private boolean success;

    private String code;

    private String msg;

    private T data;

    public static <T> Result<T> success() {
        Result<T> r = new Result<T>();
        r.setSuccess(true);
        r.setMsg(ErrorCode.SUCCESS.getDesc());
        r.setCode(ErrorCode.SUCCESS.getCode());
        return r;
    }

    public static <T> Result<T> success(String msg, T data) {
        Result<T> r = new Result<T>();
        r.setSuccess(true);
        r.setCode(ErrorCode.SUCCESS.getCode());
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static <T> Result<T> success(T data) {
        Result<T> r = new Result<T>();
        r.setSuccess(true);
        r.setCode(ErrorCode.SUCCESS.getCode());
        r.setData(data);
        r.setMsg(ErrorCode.SUCCESS.getDesc());
        return r;
    }

    public static <T> Result<T> failure(ErrorCode code) {
        return failure(code.getCode(), code.getDesc());
    }

    public static <T> Result<T> failure(String code, String message) {
        return failure(code, message, null);
    }

    public static <T> Result<T> failure(String code, String msg, T data) {
        Result<T> r = new Result<T>();
        r.setSuccess(false);
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static <T> Result<T> failure(String msg, T data) {
        Result<T> r = new Result<T>();
        r.setSuccess(false);
        r.setCode(ErrorCode.FAIL.getCode());
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static <T> Result<T> failure() {
        Result<T> r = new Result<T>();
        r.setSuccess(false);
        r.setCode(ErrorCode.FAIL.getCode());
        r.setMsg(ErrorCode.FAIL.getDesc());
        return r;
    }

    public static <T> Result<T> failure(T data) {
        Result<T> r = new Result<T>();
        r.setSuccess(false);
        r.setCode(ErrorCode.FAIL.getCode());
        r.setMsg(ErrorCode.FAIL.getDesc());
        r.setData(data);
        return r;
    }

    public static <T> Result<T> failure(ErrorCode errorCode, T data) {
        Result<T> r = new Result<T>();
        r.setSuccess(false);
        r.setCode(errorCode.getCode());
        r.setMsg(errorCode.getDesc());
        r.setData(data);
        return r;
    }

}
